package cn.yzstu.university.controller;

import cn.yzstu.university.entity.Sign;
import cn.yzstu.university.service.SignService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

/**
 * @author Baldwin
 * @mail admin@yzstu.cn
 * @blog blog.yzstu.cn
 * @since 2022/8/1 16:31
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sign" )
@Tag(name = "管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SignController {
	private final SignService signService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param sign
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page" )
	public R getSignPage(Page page, Sign sign) {
		return R.ok(signService.page(page, Wrappers.query(sign)));
	}


	/**
	 * 通过id查询
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}" )
	public R getById(@PathVariable("id" ) Long id) {
		return R.ok(signService.getById(id));
	}

	/**
	 * 新增
	 * @param sign
	 * @return R
	 */
	@Operation(summary = "新增", description = "新增")
	@SysLog("新增" )
	@PostMapping
	public R save(@RequestBody Sign sign) {
		return R.ok(signService.save(sign));
	}

	/**
	 * 修改
	 * @param sign
	 * @return R
	 */
	@Operation(summary = "修改", description = "修改")
	@SysLog("修改" )
	@PutMapping
	public R updateById(@RequestBody Sign sign) {
		return R.ok(signService.updateById(sign));
	}

	/**
	 * 通过id删除
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id删除", description = "通过id删除")
	@SysLog("通过id删除" )
	@DeleteMapping("/{id}" )
	public R removeById(@PathVariable Long id) {
		return R.ok(signService.removeById(id));
	}
}
